home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / mmailp.idb / usr / lib / Zmail / bin / sun2mime.z / sun2mime
Encoding:
Text File  |  1997-01-22  |  1.1 KB  |  44 lines

  1. #!/bin/sh -f
  2. #
  3. # This is sun2mime.  It makes a bold attempt to transform a Sun mailtool message into
  4. # MIME format.
  5. #
  6. # This program is for use with sun-message which takes an arg to figure out how
  7. # (or if) the message is encoded.
  8. #
  9. if [ x$METAMAIL_TMPDIR = x ]; then
  10.     METAMAIL_TMPDIR=/tmp
  11. fi
  12. TMPFILE=${METAMAIL_TMPDIR}/stom.$$
  13.  
  14. /bin/nawk '
  15.   BEGIN { printf("Content-type: multipart/mixed; boundary=--------\n\n")
  16.           RS=""; FS="\n"; mode="HEADER" }
  17.   mode == "HEADER" {
  18.     encoding=""
  19.     for (i=1; i<=NF; i++)
  20.       if ($i ~ /^X-Sun-Encoding-Info:/) {
  21.         encoding = sprintf ("; encoding=%s", substr($i,index($i,":")+1))
  22.       }
  23.     for (i=1; i<=NF; i++)
  24.       if ($i ~ /^X-Sun-Data-Type:/)
  25.         printf ("Content-Type:%s%s\n", substr($i,index($i,":")+1), encoding)
  26.       else
  27.         print $i
  28.     RS="\n"; FS=" "; getline; mode="BODY"; printf ("\n") }
  29.   mode == "BODY" {
  30.     if ($0 == "----------") {
  31.       print
  32.       mode="HEADER"
  33.       RS=""; FS="\n"
  34.     }
  35.     else
  36.       print
  37.   }
  38.   END { printf("----------\n") }
  39. ' $1 > $TMPFILE
  40.  
  41. metamail -z $TMPFILE
  42. rm -f $TMPFILE
  43.  
  44.